/****************************************************************************
 Copyright (c) 2012-2012 lijiejun
 Copyright (c) 2010-2012 cocos2d-x.org
 Copyright (c) 2008-2010 Ricardo Quesada
 Copyright (c) 2011      Zynga Inc.
 
 http://www.cocos2d-x.org
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

package org.cocos2d.basenodes
{
	import org.cocos2d.CCCamera;
	import org.cocos2d.cocoa.CCObject;
	import org.cocos2d.cocoa.CCPoint;
	import org.cocos2d.cocoa.CCSize;
	import org.cocos2d.support.CCPointExtension;
	
	public class CCNode
	{
		protected var m_tPosition : CCPoint;
		
		public function get Position() : CCPoint
		{
			return m_tPosition;
		}
		
		public function set Position(value : CCPoint) : void
		{
			m_tPosition = value;
		}
		
		protected var m_bIsVisible : Boolean;
		
		public function get Visible() : Boolean
		{
			return m_bIsVisible;
		}
		
		public function set Visible(value : Boolean) : void
		{
			m_bIsVisible = value;
		}
		
		protected var m_pChildren : Vector.<CCObject> = new Vector.<CCObject>();
		
		public function get Children() : Vector.<CCObject>
		{
			return m_pChildren;
		}
		
		protected var m_pCamera : CCCamera;
		
		public function get Camera() : CCCamera
		{
			if (!m_pCamera)
			{
				m_pCamera = new CCCamera();
			}
			
			return m_pCamera;
		}
		
		protected var m_tAnchorPoint : CCPoint;
		
		public function get AnchorPoint() : CCPoint
		{
			return m_tAnchorPoint;
		}
		
		public function set AnchorPoint(point : CCPoint) : void
		{
			if (!CCPoint.CCPointEqualToPoint(point, m_tAnchorPoint))
			{
				m_tAnchorPoint = point;
				m_tAnchorPointInPoints = CCPointExtension.ccp(m_tContentSize.width * m_tAnchorPoint.x, m_tContentSize.height * m_tAnchorPoint.y);
				m_bIsTransformDirty = m_bIsInverseDirty = true;
			}
		}
		
		protected var m_tAnchorPointInPoints : CCPoint;
		
		public function get AnchorPointInPoints() : CCPoint
		{
			return m_tAnchorPointInPoints;
		}
		
		public var m_bIsRunning : Boolean;
		
		public function get IsRunning() : Boolean
		{
			return m_bIsRunning;
		}
		
		protected var m_bIgnoreAnchorPointForPosition : Boolean;
		
		public function get IgnoreAnchorPointForPosition() : Boolean
		{
			return m_bIgnoreAnchorPointForPosition;
		}
		
		public function set IgnoreAnchorPointForPosition(isIgnoreAnchorPointForPosition : Boolean) : void
		{
			if (isIgnoreAnchorPointForPosition != m_bIgnoreAnchorPointForPosition)
			{
				m_bIgnoreAnchorPointForPosition = isIgnoreAnchorPointForPosition;
				m_bIsTransformDirty = m_bIsInverseDirty = true;
			}
		}
		
		protected var m_tContentSize : CCSize;
		
		public function get ContentSize() : CCSize
		{
			return m_tContentSize;	
		}
		
		public function set ContentSize(size : CCSize) : void
		{
			if (!CCSize.CCSizeEqualToSize(size, m_tContentSize))
			{
				m_tContentSize = size;
				
				m_tAnchorPointInPoints = CCPointExtension.ccp(m_tContentSize.width * m_tAnchorPoint.x, m_tContentSize.height * m_tAnchorPoint.y);
				m_bIsTransformDirty = m_bIsInverseDirty = true;
			}
		}
		
		protected var m_pParent : CCNode;
		
		public function get Parent() : CCNode
		{
			return m_pParent;
		}
		
		public function set Parent(value : CCNode) : void
		{
			m_pParent = value;
		}
		
		protected var m_nTag : int;
		
		public function get Tag() : int
		{
			return m_nTag;
		}
		
		public function set Tag(value : int) : void
		{
			m_nTag = value;
		}
		
		protected var m_bIsTransformDirty : Boolean;
		protected var m_bIsInverseDirty : Boolean;
		
		public function CCNode()
		{
			m_tAnchorPoint = CCPoint.Zero;
			m_tAnchorPointInPoints = CCPoint.Zero;
			m_tContentSize = CCSize.Zero;
			m_bIgnoreAnchorPointForPosition = false;
			m_bIsTransformDirty = true;
			m_bIsInverseDirty = true;
		}
		
		/*
		public function addChild(child : CCNode, zOrder : int) : void
		{
			if (child == null) throw new Error("Argument must be non-nil");
			this.addChild(child, zOrder, child.m_nTag);
		}
		*/
		
		public function addChild(child : CCNode, zOrder : int, tag : int = -1) : void
		{
			if (child == null) throw new Error("Argument muse be non-nil");
			if (tag == -1)
			{
				tag = child.m_nTag;
			}
			
		}
	}
}